package com.dynamicthreadpool.spi.support;

import com.dynamicthreadpool.spi.QueueFactory;
import com.dynamicthreadpool.spi.URL;
import java.util.concurrent.*;

/**
 * 用于贪婪线程池的队列工厂
 */
public class TaskQueueFactory implements QueueFactory {

    @Override
    public BlockingQueue<Runnable> createQueue(URL url) {
        int queues = url.getParameter("queues", 0);
        // 使用LinkedBlockingQueue作为替代，因为TaskQueue是EagerThreadPool的内部类
        return new LinkedBlockingQueue<>(queues <= 0 ? 200 : queues);
    }
}